<template>
	<view class="main">
		<view class="return" @click="toReturn()" style="box-shadow: 1rpx 2rpx 4rpx 2rpx gainsboro;">
			<u-icon name="arrow-left" size="20"></u-icon>
		</view>
		<!-- <u-tabs :list="routeList" @click="click" :activeStyle="activeStyle" lineColor="#00AF91"></u-tabs> -->
		<image src="/static/bg3.png" class="bg"></image>
		<view class="search">
			<u-search bgColor="#ffffff" placeholder="输入搜索内容" :showAction="false" v-model="keyword"
				@change="toChange()"></u-search>
		</view>
		<navigator :url="'/pages/route/detail?id='+item.id" hover-class="none" class="list" v-for="(item,index) in list"
			:key="index">
			<image :src="item.cover" mode="aspectFill"></image>
			<view class="infos">
				<view class="title">{{item.name}}</view>
				<view class="flex time" v-if="item.open_time!=''">
					<u-icon name="clock-fill"></u-icon>
					<view>{{item.open_time}}
					</view>
				</view>
				<view class="flex time">
					<u-icon name="map-fill"></u-icon>
					<view>{{item.address}}</view>
				</view>
			</view>

		</navigator>
		<xw-empty :isShow="empty" text="暂无数据" textColor="#777777"></xw-empty>
	</view>
</template>

<script>
	import {
		scenicList,
		scenicCategory
	} from '@/api/apiData.js';
	export default {
		data() {
			return {
				activeStyle:{
					color:'#00AF91'
				},
				keyword: '',
				totalPage: 1,
				page: 0,
				offset: 10,
				list: [],
				scrollTop: 0,
				empty: false,
				loadText: {
					loadmore: '点击或上拉加载更多',
					loading: '努力加载中',
					nomore: '实在没有了'
				},
				status: 'loadmore',
				category_id: 2,
				list1: [{
					id:2,
					name: '全部',
				}],
				routeList: [{
					id:2,
					name: '全部',
				}],
			};
		},
		onPageScroll(e) {
			const that = this;
			that.scrollTop = e.scrollTop;
		},
		onReachBottom() {
			const that = this;
			that.getlist();
		},
		onLoad() {
			this.scenicCategory()
			this.getlist()
		},
		methods: {
			click(e){
				this.category_id = e.id
				this.list =[]
				this.page = 0
				this.getlist()
			},
			async scenicCategory() {
				const result = await scenicCategory({
					parent_id: 2
				})
				if (result.code == 1) {
					console.log(result.data)
					this.routeList=this.routeList.concat(result.data)
				} else {
					uni.showToast({
						title: result.msg,
						icon: 'error'
					});
				}
			},
			toChange() {
				this.page = 0
				this.list = []
				this.getlist()
			},
			toReturn() {
				uni.navigateBack()
			},
			async getlist() {
				const that = this;
				const {
					totalPage,
					page,
					offset,
					list,
					keyword,
					category_id
				} = that;
				let obj = {
					size: offset,
					page: page + 1,
					category_id:category_id,
					name: keyword
				};
				that.status = 'loading';
				if (totalPage > page) {
					let result = await scenicList(obj);
					if (result.code == 1) {
						that.page = page + 1;
						if (result.data.total == 0) {
							that.empty = true;
							that.status = 'nomore';
							return;
						}
						that.empty = false;
						setTimeout(() => {
							that.status = 'loadmore';
						}, 500);
						that.list = list.concat(result.data.list);
						that.totalPage = Math.ceil(result.data.total / offset);
					}
				} else {
					setTimeout(() => {
						that.status = 'nomore';
					}, 500);
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	page {
		padding-bottom: 100rpx;
	}

	.bg {
		position: fixed;
		width: 100%;
		height: 100%;
		top: 0;
		left: 0;
		z-index: -1;
	}

	.main {
		padding-top: 80rpx;
		margin: 0 30rpx;

		.search {
			box-shadow: 1rpx 2rpx 10rpx 1rpx gainsboro;
			border-radius: 50rpx;
			margin-top: 20rpx;
		}

		.list {
			border-radius: 16rpx;
			background: white;
			box-shadow: 1rpx 2rpx 10rpx 1rpx gainsboro;
			margin-top: 30rpx;

			image {
				border-radius: 16rpx 16rpx 0rpx 0rpx;
				height: 336rpx;
				width: 100%;
			}

			.infos {
				padding: 16rpx;

				.title {
					font-size: 32rpx;
					margin-bottom: 16rpx;
				}

				.time {
					color: #6C7A94;
					font-size: 24rpx;
					margin-bottom: 6rpx;

					view {
						margin-right: 6rpx;
					}
				}
			}
		}
	}
</style>